//	获取url传值
function getQueryString(name) {
	var result = window.location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
	if (result == null || result.length < 1) {return "";}
		return result[1];
}
id = getQueryString("id");
$(function(){
	if($(".admin").height()<600){
		$('.nav-btn').height('50px').find('img').hide();
	}else{
		$('.nav-btn').height('150px').find('img').show();
	}
})
//	供应商详情
	var currentPage = 1; 
	ajaxTest(currentPage);
	
	function ajaxTest(currentPage) {
		$.ajax({
				type:"post",
				url:serverIP+"/user/goodsInfo/list",
				dataType:"json",
				xhrFields: {
	                withCredentials: true    // 设置sessionId相同
	            },
	            data: {goodsId:id},
				success:function (data) {
					if(data.code==0){
						let result=data.data.list.result;
						var strVar = "";
						result.map(function(u){
							strVar += "              <tr>";
						    strVar += "                <td id=\"id\">"+u.goodsInfoId+"<\/td>\n";
						    strVar += "                <td>"+u.goodsName+"<\/td>\n";
						    strVar += "                <td>"+u.goodsCode+"<\/td>\n";
						    strVar += "                <td>"+u.goodsBarCode+"<\/td>\n";
						    strVar += "                <td>"+u.propertyName+"<\/td>\n";
						    strVar += "                <td>"+u.supplier+"<\/td>\n";
						    strVar += "                <td>"+u.sum+"<\/td>\n";
						    strVar += "                <td>"+u.remark+"<\/td>\n";
						    strVar += "                <td>\n"; 
						    strVar += "                		<div>\n"; 
						    strVar += "                			<span class=\"btn edit\" value="+u.goodsInfoId+">\n"; 
						    strVar += "                				<i class=\"icon-edit\"></i>修改\n"; 
						    strVar += "                			</span>\n"; 
						    strVar += "                			<span class=\"btn delete\" value="+u.goodsInfoId+">\n"; 
						    strVar += "                				<i class=\"icon-trash\"></i>删除\n"; 
						    strVar += "                			</span>\n";
						    strVar += "                		</div>\n";
						    strVar += "                <\/td>\n"; 
						    strVar += "              <\/tr>";
						})
						$('.print-tbody').html(strVar);
					//分页
						$("#page").paging({
							pageNo: data.data.list.curPage,
							totalPage: data.data.list.totalPage,
							totalSize: data.data.list.totalRow,
							callback: function(currentPage) {
								ajaxTest(currentPage); 
							}
						});
					}else{
						alert(data.msg);
					}/*if-End*/
				}
		})
	}
$(".add").click(function(){
	window.location.href="stock1-enter.html?id="+id;
})
$("body").on("click",".edit",function(){
	var tid=$(this).attr("value");
	window.location.href="stock1-edit.html?id="+tid;
})
$("body").on("click",".delete",function(){
	if(confirm("确定要删除本条信息么")){
		var gid=$(this).attr("value");
		$.ajax({  
	        type : "POST",  
	        url : serverIP+'/user/goodsInfo/del',  
	        data : {
	        	goodsInfoId:gid
	        },
	        xhrFields: {
	            withCredentials: true    // 设置sessionId相同
	        },
	        success : function(data){  
	        	if(data.code==0){
	        		alert("删除成功");
	        		window.location.reload();
	        	}else{
	        		alert(data.msg);
	        	}
	        }  
	    });
	}
});   
//监听浏览器窗口变化
window.onresize = function(){
	var bodyH=$("body").height();
	$(".leftbar").height(bodyH-45+"px");
	$(".content").height(bodyH-45+"px");
	$(".admin").height($(".content").height()-45+"px");
	if($(".admin").height()<600){
		$('.nav-btn').height('50px').find('img').hide();
	}else{
		$('.nav-btn').height('150px').find('img').show();
	}
}